package com.hifar.demo3;

import java.io.FileInputStream;
import java.io.InputStream;

import com.hifar.demo3.model.DmData;
import com.hifar.demo3.model.DmTable;
import com.hifar.demo3.model.ProcedureStep;
import com.hifar.demo3.pojo.TableRow;

public class S1000DParserExample {
    public static void main(String[] args) {
        S1000DParser parser = new S1000DParser();
        
        try (InputStream is = new FileInputStream("src/main/resources/data/DXJG0001A.xml")) {
            DmData dmData = parser.parse(is);
            
            // 输出解析结果
            System.out.println("DM标识: " + dmData.getDmIdent().getTechName());
            System.out.println("DM编码: " + dmData.getDmIdent().getDmCode());
            System.out.println("版本: " + dmData.getDmIdent().getIssueNumber());
            
            System.out.println("\n前提要求:");
            System.out.println("条件: " + dmData.getPreliminaryRequirements().getConditions());
            System.out.println("供应品: " + dmData.getPreliminaryRequirements().getSupplies());
            
            System.out.println("\n主程序步骤:");
            for (ProcedureStep step : dmData.getMainProcedureSteps()) {
                printProcedureStep(step, 0);
            }
            
            System.out.println("\n表格数据:");
            for (DmTable table : dmData.getTables()) {
                System.out.println("表格: " + table.getTitle());
                for (TableRow row : table.getRows()) {
                    System.out.println("行: " + row.getCells());
                }
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private static void printProcedureStep(ProcedureStep step, int indent) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < indent; i++) {
            sb.append("  ");
        }
        sb.append(step.getTitle()).append(": ").append(step.getDescription());
        System.out.println(sb.toString());
        
        if (step.getSubSteps() != null) {
            for (ProcedureStep subStep : step.getSubSteps()) {
                printProcedureStep(subStep, indent + 1);
            }
        }
    }
}